package de.koller.altitude.engine.physics;

import de.koller.altitude.ANode;
import de.koller.altitude.engine.entity.MovingObject;
import de.koller.oceanFramework.math.RVec3;

public class MOPhysics extends ANode {

	private MovingObject mo;
	
	public void physicStep( MovingObject mo, int elapsedTime ) {
		this.mo = mo;
		
		mo.location.updatePosition( mo.movement, elapsedTime );
		mo.afterPhysicsSteps();
		
		if( mo.physicsParameters.bindToFloor )
			boundToFloor();
	}
	
	private void boundToFloor() {
		RVec3 fs = aroot.engine.floor.size.size;
		RVec3 mol = mo.location.position;
		RVec3 mos = mo.size.size;
		
		if( mol.x + mos.x*.5f > fs.x ) mol.x = fs.x - mos.x*.5f;
		if( mol.z + mos.z*.5f > fs.z ) mol.z = fs.z - mos.z*.5f;
		if( mol.x - mos.x*.5f < 0 )	   mol.x = 0 + mos.x*.5f;
		if( mol.z - mos.z*.5f < 0 )	   mol.z = 0 + mos.z*.5f;
	}
	
}
